package com.tanhua.dubbo.api.db;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.BlackList;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.dubbo.mapper.BlackListMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**黑名单问题服务接口实现类
 */
@Service
public class BlackListApiImpl implements BlackListApi{

    @Autowired
    private BlackListMapper blackListMapper;

    /**
     * 分页查询黑名单数据
     */
    @Override
    public PageResult<UserInfo> queryPageByUserId(Long page, Long pagesize, Long userId) {
        //1.设置分页参数
        Page pageParam = new Page(page,pagesize);
        //2.调用自定义分页方法查询分页数据
        IPage<UserInfo> iPage = blackListMapper.queryPageByUserId(pageParam, userId);
        //3.封装数据返回 总记录数 每页显示记录数 总页码 当前页码 当前页码显示黑名单数据
        return new PageResult<UserInfo>(iPage.getTotal(),iPage.getSize(),iPage.getPages(),iPage.getCurrent(),iPage.getRecords());
    }

    /**
     * 根据当前用户id 和 黑名单用户id删除 黑名单记录
     */
    @Override
    public void deleteById(Long blackUserId, Long currentUserId) {
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",currentUserId);
        queryWrapper.eq("black_user_id",blackUserId);
        blackListMapper.delete(queryWrapper);
    }
}
